package com.codes.core.stringuu;


import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description 
 * @Date 2020/7/20 17:56
 * @Created  peanut
 */
public class StringUU {

    public static void main(String[] args) {

        String s = "1,2,3,4,5";
        String ss = "1,2,3,4,5,";
        String sss = null;
        String ssss = ",";
        String sssss = "";

        List<String> list =str2List(ss,",");

        System.out.println(list.size());


    }

    public static List  str2List(String str,String separator){
        List list = new ArrayList(30);
        if (StringUtils.isNotBlank(str)){
            return Arrays.asList(cutLastChar(str).split(separator));
        }
        return list;
    }

    /**
     *  最后一个 是 逗号 就     截掉
     * @param str
     * @return
     */
    public static String cutLastChar(String str){
        if (null != str ){
            String lastChar = getLastChar(str);
            if (",".equals(lastChar)){
                return str.substring(0,str.length() - 1);
            }
            return str;
        }

        return null;
    }

    public static String getLastChar(String str){

        if (null != str && 0 < str.length()){
            if (1 == str.length()){
                return str;
            }
            return str.substring(str.length() - 1);

        }
        return null;
    }


}